<?php
require_once("vcl/vcl.inc.php");
require_once("lib/db_connection.php");
//Includes
use_unit("components4phpfull/jtdivwindow.inc.php");
use_unit("components4phpfull/jtgroupbox.inc.php");
use_unit("components4phpfull/jtjavascript.inc.php");
use_unit("comctrls.inc.php");
use_unit("components4phpfull/jtdatepicker.inc.php");
use_unit("components4phpfull/jtsitetheme.inc.php");
use_unit("forms.inc.php");
use_unit("extctrls.inc.php");
use_unit("stdctrls.inc.php");

//Class definition
class pop_tire_create extends Page
{
       public $Label17 = null;
       public $Label11 = null;
       public $Label13 = null;
       public $Label10 = null;
       public $Label4 = null;
       public $Label19 = null;
       public $lblpressure = null;
       public $lbltd = null;
       public $lblcpressure = null;
       public $Label18 = null;
       public $edcurrpsi = null;
       public $Label16 = null;
       public $edPsi = null;
       public $lblctd = null;
       public $Label15 = null;
       public $edCurrTreadDepth = null;
       public $Label14 = null;
       public $edTreadDepth = null;
       public $lblrecap = null;
       public $lblbrand = null;
       public $edRecap = null;
       public $Label9 = null;
       public $edBranding = null;
       public $Label5 = null;
       public $JSValidate = null;
       public $hfError = null;
       public $lblid = null;
       public $Label12 = null;
       public $JTDivSize = null;
       public $JTGroupBox3 = null;
       public $btnAddSize = null;
       public $btnDelSize = null;
       public $edSize = null;
       public $listSize = null;
       public $JTDivType = null;
       public $JTGroupBox1 = null;
       public $btnAddType = null;
       public $btnDelType = null;
       public $edType = null;
       public $listType = null;
       public $JTDivMnfr = null;
       public $JTGroupBox2 = null;
       public $btnAddMnfr = null;
       public $btnDelMnfr = null;
       public $edMnfr = null;
       public $listMnfr = null;
       public $compid = null;
       public $JTJavaScript9 = null;
       public $JTJavaScript8 = null;
       public $JTJavaScript7 = null;
       public $JTJavaScript6 = null;
       public $JTJavaScript5 = null;
       public $JTJavaScript4 = null;
       public $JTJavaScript3 = null;
       public $JTJavaScript2 = null;
       public $JTJavaScript1 = null;
       public $btnShowSize = null;
       public $btnShowMnfr = null;
       public $btnShowType = null;
       public $JTDateWarr = null;
       public $JTDatePurch = null;
       public $btnCancel = null;
       public $btnSubmit = null;
       public $Image1 = null;
       public $cmbVendor = null;
       public $edCost = null;
       public $cmbSize = null;
       public $cmbMnfr = null;
       public $cmbType = null;
       public $edTireID = null;
       public $Label8 = null;
       public $Label6 = null;
       public $JTSiteTheme1 = null;
       public $Label2 = null;
       public $Label1 = null;
       public $Label7 = null;
       public $lblVendorNum = null;
       function edCostJSKeyUp($sender, $params)
       {

       ?>
       //Add your javascript code here
       //accept only numbers
       var numero = document.getElementById("edCost").value;
       var first = numero.indexOf('.');
       var last = numero.lastIndexOf('.');

       while(isNaN(numero))
       {
        haba = numero.length;
        haba = haba - 1;
        numero = numero.substr(0,haba);
       }

       while(first!=last)
       {
        numero = numero.slice(0,last);
        first = numero.indexOf('.');
        last = numero.lastIndexOf('.');
       }
       document.getElementById("edCost").value = numero;
       <?php

       }

       function edcurrpsiJSBlur($sender, $params)
       {

       ?>
       //Add your javascript code here
       validateRequire('edcurrpsi','lblcpressure');
       <?php

       }

       function edPsiJSBlur($sender, $params)
       {

       ?>
       //Add your javascript code here
       validateRequire('edPsi','lblpressure');
       <?php

       }

       function edCurrTreadDepthJSBlur($sender, $params)
       {

       ?>
       //Add your javascript code here
       validateRequire('edCurrTreadDepth','lblctd');
       <?php

       }


       function edTreadDepthJSBlur($sender, $params)
       {

       ?>
       //Add your javascript code here
       validateRequire('edTreadDepth','lbltd');
       <?php

       }

       function edRecapJSBlur($sender, $params)
       {

       ?>
       //Add your javascript code here
       validateRequire('edRecap','lblrecap');
       <?php

       }

       function edBrandingJSBlur($sender, $params)
       {

       ?>
       //Add your javascript code here
       validateRequire('edBranding','lblbrand');
       <?php

       }


       function edTireIDJSBlur($sender, $params)
       {

       ?>
       //Add your javascript code here
       validateRequire('edTireID','lblid');
       <?php

       }

       function pop_tire_createJSLoad($sender, $params)
       {
       $this->clr_tire();
       ?>
       //Add your javascript code here

       <?php

       }



       function btnDelSizeJSClick($sender, $params)
       {

       ?>
       //Add your javascript code here
       var SizeIndex = document.getElementById('listSize').selectedIndex;
       var SizeValue = document.getElementById('listSize')[SizeIndex].value;
       var compider3 = document.getElementById('compid').value;
       AjaxSize3(SizeValue,compider3);
       <?php

       }

       function btnAddSizeJSClick($sender, $params)
       {

       ?>
       //Add your javascript code here
       var addsize = document.getElementById('edSize').value;
       var compider = document.getElementById('compid').value;
       AjaxSize2(addsize,compider);
       document.tire_create.edSize.value = "";
       <?php

       }


       function btnShowSizeJSClick($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.getElementById('JTDivSize').Show();
       document.tire_create.edSize.value = "";
       <?php

       }

       function btnDelMnfrJSClick($sender, $params)
       {

       ?>
       //Add your javascript code here
       var MnfrIndex = document.getElementById('listMnfr').selectedIndex;
       var MnfrValue = document.getElementById('listMnfr')[MnfrIndex].value;
       var compider3 = document.getElementById('compid').value;
       AjaxMnfr3(MnfrValue,compider3);
       <?php

       }

       function btnAddMnfrJSClick($sender, $params)
       {

       ?>
       //Add your javascript code here
       var addmnfr = document.getElementById('edMnfr').value;
       var compider = document.getElementById('compid').value;
       AjaxMnfr2(addmnfr,compider);
       document.tire_create.edMnfr.value = "";
       <?php

       }

       function btnShowMnfrJSClick($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.getElementById('JTDivMnfr').Show();
       document.tire_create.edMnfr.value = "";
       <?php

       }

       function btnDelTypeJSClick($sender, $params)
       {

       ?>
       //Add your javascript code here
       var TypeIndex = document.getElementById('listType').selectedIndex;
       var TypeValue = document.getElementById('listType')[TypeIndex].value;
       var compider3 = document.getElementById('compid').value;
       AjaxType3(TypeValue,compider3);
       <?php

       }

       function btnAddTypeJSClick($sender, $params)
       {

       ?>
       //Add your javascript code here
       var addtype = document.getElementById('edType').value;
       var compider = document.getElementById('compid').value;
       AjaxType2(addtype,compider);
       document.tire_create.edType.value = "";
       <?php

       }

       function btnShowTypeJSClick($sender, $params)
       {

       ?>
       //Add your javascript code here
      document.getElementById('JTDivType').Show();
       document.tire_create.edType.value = "";
       <?php

       }


       function btnCancelJSClick($sender, $params)
       {

       ?>
       window.close();
       <?php

       }

       function btnCancelClick($sender, $params)
       {
       redirect('tire_list.php?company_id='.$_SESSION['company_id']);
       }

       function clr_tire()
       {
      $this->edTireID->Text = '';
       $this->edBranding->Text = '';
       $this->edRecap->Text = '';
       $this->JTDatePurch->Text = date('Y-m-d');
       $this->edCost->Text = '';
       $this->JTDateWarr->Text = date('Y-m-d');
       $this->edCurrTreadDepth->Text = '';
       $this->edTreadDepth->Text = '';
       $this->edPsi->Text = '';
       $this->edcurrpsi->Text = '';

       $this->cmbType->Clear();
       $this->cmbType->AddItem('--Select--', null, null);
       $this->cmbType->setItemIndex('--Select--', null, null);
       $result_type = mysql_query("select * from lookup_tire_tbl where company_id = '".$_SESSION['company_id']."' AND category='types'");

       while($row_type = mysql_fetch_array($result_type))
        {
            $this->cmbType->AddItem($row_type['value'], null, $row_type['value']);
        }

       $this->cmbMnfr->Clear();
       $this->cmbMnfr->AddItem('--Select--', null, null);
       $this->cmbMnfr->setItemIndex('--Select--', null, null);
       $result_mnfr = mysql_query("select * from lookup_tire_tbl where company_id = '".$_SESSION['company_id']."' AND category='manufacturers'");

        while($row_mnfr = mysql_fetch_array($result_mnfr))
        {
            $this->cmbMnfr->AddItem($row_mnfr['value'], null, $row_mnfr['value']);
        }

       $this->cmbSize->Clear();
       $this->cmbSize->AddItem('--Select--', null, null);
       $this->cmbSize->setItemIndex('--Select--', null, null);
       $result_size = mysql_query("select * from lookup_tire_tbl where company_id = '".$_SESSION['company_id']."' AND category='sizes'");

       while($row_size = mysql_fetch_array($result_size))
       {
            $this->cmbSize->AddItem($row_size['value'], null, $row_size['value']);
       }

        $this->cmbVendor->Clear();
        $this->cmbVendor->AddItem('--Select--', null, null);
        $this->cmbVendor->setItemIndex('--Select--', null, null);
        $result_vend = mysql_query("select * from vendor_tbl where company_id='1'");

        while($row_vend = mysql_fetch_array($result_vend))
        {
            $this->cmbVendor->AddItem($row_vend['vendor_name'], null, $row_vend['vendor_name']);
        }


       }


       function validateRequired($value, $lbl)
       {
          if($value == '' || $value == null)
          {
             $this->$lbl->Caption = '&darr; This field is required &darr;';
             $this->hfError->setValue('1');
          }
       }

       function pop_tire_createCreate($sender, $params)
       {
       $this->hfError->setValue('0');
       $this->lblid->Caption = '';
       $this->lblpressure->Caption = '';
       $this->lblcpressure->Caption = '';
       $this->lblctd->Caption = '';
       $this->lblrecap->Caption = '';
       $this->lblbrand->Caption = '';
       $this->lbltd->Caption = '';

       $this->clr_tire();

       $this->compid->Value = $_SESSION['company_id'];
       $this->cmbType->Clear();
       $this->cmbType->AddItem('--Select--', null, null);
       $result_type = mysql_query("select * from lookup_tire_tbl where company_id = '".$_SESSION['company_id']."' AND category='types'");

       while($row_type = mysql_fetch_array($result_type))
        {
            $this->cmbType->AddItem($row_type['value'], null, $row_type['value']);
        }

        //list type
        $result_t = mysql_query("select * from lookup_tire_tbl where company_id = '".$_SESSION['company_id']."' AND category='types'");

        while($row_t = mysql_fetch_array($result_t))
        {
            $this->listType->AddItem($row_t['value'], null, $row_t['value']);
        }


       $this->cmbMnfr->Clear();
       $this->cmbMnfr->AddItem('--Select--', null, null);
        $result_mnfr = mysql_query("select * from lookup_tire_tbl where company_id = '".$_SESSION['company_id']."' AND category='manufacturers'");

        while($row_mnfr = mysql_fetch_array($result_mnfr))
        {
            $this->cmbMnfr->AddItem($row_mnfr['value'], null, $row_mnfr['value']);
        }

        //list manufacturer
       $result_m = mysql_query("select * from lookup_tire_tbl where company_id = '".$_SESSION['company_id']."' AND category='manufacturers'");

        while($row_m = mysql_fetch_array($result_m))
        {
            $this->listMnfr->AddItem($row_m['value'], null, $row_m['value']);
        }


        $this->cmbSize->Clear();
        $this->cmbSize->AddItem('--Select--', null, null);
        $result_size = mysql_query("select * from lookup_tire_tbl where company_id = '".$_SESSION['company_id']."' AND category='sizes'");

        while($row_size = mysql_fetch_array($result_size))
        {
            $this->cmbSize->AddItem($row_size['value'], null, $row_size['value']);
        }

         //list size
        $result_s = mysql_query("select * from lookup_tire_tbl where company_id = '".$_SESSION['company_id']."' AND category='sizes'");

        while($row_s = mysql_fetch_array($result_s))
        {
            $this->listSize->AddItem($row_s['value'], null, $row_s['value']);
        }

        $this->cmbVendor->Clear();
        $this->cmbVendor->AddItem('--Select--', null, null);
        $result_vend = mysql_query("select * from vendor_tbl where company_id='".$_SESSION['company_id']."'");

        while($row_vend = mysql_fetch_array($result_vend))
        {
            $this->cmbVendor->AddItem($row_vend['vendor_name'], null, $row_vend['vendor_name']);
        }

       $this->edTireID->Text = '';
       $this->edBranding->Text = '';
       $this->edRecap->Text = '';
       $this->JTDatePurch->Text = '';
       $this->edCost->Text = '';
       $this->JTDateWarr->Text = '';
       $this->edCurrTreadDepth->Text = '';
       $this->edTreadDepth->Text = '';
       $this->edPsi->Text = '';
       $this->edcurrpsi->Text = '';
       }

       function btnSubmitClick($sender, $params)
       {
       $this->validateRequired($this->edTireID->Text, 'lblid');
       //$this->validateRequired($this->edBranding->Text, 'lblbrand');
       //$this->validateRequired($this->edcurrpsi->Text, 'lblcpressure');
       //$this->validateRequired($this->edPsi->Text, 'lblpressure');
       //$this->validateRequired($this->edCurrTreadDepth->Text, 'lblctd');
       //$this->validateRequired($this->edTreadDepth->Text, 'lbltd');
       //$this->validateRequired($this->edRecap->Text, 'lblrecap');
       $error = $this->hfError->getValue();
       if($error == '1' || $number != $key)
       {
          $this->hfError->setValue('0');
          return false;
       }
       else if($error == '0')
       {
       mysql_query("INSERT INTO tire_inventory_tbl(company_id,
       tire_SN,
       branding,
       recap,
       vendor,
       purch_date,
       cost,
       type,
       warr_expiration,
       manufacturer,
       size,
       tread_depth,
       curr_tread,
       psi,
       curr_psi)

       VALUES
       ('".$_SESSION['company_id']."',
       '".$this->edTireID->Text."',
       '".$this->edBranding->Text."',
       '".$this->edRecap->Text."',
       '".$this->cmbVendor->getItemIndex()."',
       '".$this->JTDatePurch->Text."',
       '".$this->edCost->Text."',
       '".$this->cmbType->getItemIndex()."',
       '".$this->JTDateWarr->Text."',
       '".$this->cmbMnfr->getItemIndex()."',
       '".$this->cmbSize->getItemIndex()."',
       '".$this->edCurrTreadDepth->Text."',
       '".$this->edTreadDepth->Text."',
       '".$this->edPsi->Text."',
       '".$this->edcurrpsi->Text."')") or die("INSERT TIRE - ".mysql_error());


       //redirect('tire_list.php?company_id='.$_SESSION['company_id']);
       echo "<script language=javascript>
       window.opener.location.reload();
       window.close();
       </script>";
       }
       }

}

global $application;

global $pop_tire_create;

//Creates the form
$pop_tire_create=new pop_tire_create($application);

//Read from resource file
$pop_tire_create->loadResource(__FILE__);

//Shows the form
$pop_tire_create->show();

?>